package com.exwave.socialgame.model_society.controller;

import com.exwave.socialgame.model_society.entity.Comments;
import com.exwave.socialgame.model_society.service.CommentsService;
import com.exwave.socialgame.myutils.WolfGameUtils;
import com.exwave.socialgame.myutils.ParamsException;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * (Comments)表控制层
 *
 * @author makejava
 * @since 2021-12-14 17:14:38
 */
@ApiIgnore
@RestController("评论相关")
@RequestMapping("comments")
public class CommentsController {
    /**
     * 服务对象
     */
    @Resource
    private CommentsService commentsService;

    @PostMapping("addComment")
    @ApiOperation("提交评论")
    public Object addComment(Comments comments) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            this.commentsService.insert(comments);
            comments = this.commentsService.queryById(comments.getId());
            map.put("comment", comments);
        } catch (ParamsException p) {
            return WolfGameUtils.returnFailure(p.getCode(), p.getMsg());
        } catch (Exception e) {
            return WolfGameUtils.returnFailure(e.getMessage());
        }
        return WolfGameUtils.returnSuccess(map);
    }

    @PostMapping("getComments")
    @ApiOperation("获取帖子的评论")
    public Object getComments(int oid, int offset, int limit) {
        HashMap<String, Object> map = new HashMap<>();
        List<Comments> commentsList = new ArrayList<>();
        try {
            commentsList = this.commentsService.queryByOid(oid, offset, limit);
            map.put("comments", commentsList);
        } catch (ParamsException p) {

        } catch (Exception e) {

        }
        return WolfGameUtils.returnSuccess(map);
    }
}